package com.sfzd5.html;

import javax.swing.text.*;
import javax.swing.text.html.HTML;

public class MyHTMLFactory implements ViewFactory {
    private ViewFactory defaultFactory;
    public MyHTMLFactory(ViewFactory defaultFactory){
        this.defaultFactory = defaultFactory;
    }

    public View create(Element elem) {
        AttributeSet attrs = elem.getAttributes();
        Object elementName = attrs.getAttribute(AbstractDocument.ElementNameAttribute);
        Object o = (elementName != null) ? null : attrs.getAttribute(StyleConstants.NameAttribute);
        if (o instanceof HTML.Tag) {
            HTML.Tag kind = (HTML.Tag) o;
            if (kind == HTML.Tag.IMG) {
                return new MyImageView(elem);
/*
                String srcStr = (String)elem.getAttributes().getAttribute(HTML.Attribute.SRC);
                if (srcStr != null && !srcStr.isEmpty()) {
                    //载入BASE64图片
                    if (srcStr.startsWith("data:image")) {
                        return new MyImageView(elem);
                    }
                }
*/
            }
        }
        return defaultFactory.create(elem);
    }
}
